// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   file_draft_ok.java

package draft.crm;

import include.get_name_from_ID.getNameFromID;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import include.operateDB.CdefineUpdate;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class file_draft_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;
	nseer_db_backup1 erp_db;
	getNameFromID getNameFromID;

	public file_draft_ok()
	{
		erp_db = null;
		getNameFromID = new getNameFromID();
	}

	public synchronized void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			counter count = new counter(dbApplication);
			getNameFromID getNameFromID = new getNameFromID();
			ValidataTag vt = new ValidataTag();
			nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication);
			if (crm_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String config_id = request.getParameter("config_id");
				String customer_ID = request.getParameter("customer_ID");
				String fileKind_chain = request.getParameter("fileKind_chain");
				String chain_id = Divide1.getId(fileKind_chain);
				String chain_name = Divide1.getName(fileKind_chain);
				String oldKind_chain = request.getParameter("oldKind_chain");
				String oldChain_id = Divide1.getId(oldKind_chain);
				String sales_name = "";
				String sales_ID = request.getParameter("sales_ID");
				String sql2 = (new StringBuilder("select id from crm_config_file_kind where chain_ID='")).append(chain_id).append("'").toString();
				ResultSet rs2 = crm_db.executeQuery(sql2);
				if (!sales_ID.equals(""))
					sales_name = getNameFromID.getNameFromID((String)dbSession.getAttribute("unit_db_name"), "hr_file", "human_id", sales_ID, "human_name");
				if (rs2.next())
				{
					String customer_name = request.getParameter("customer_name");
					String customer_address = request.getParameter("customer_address");
					String type = request.getParameter("type");
					String customer_class = request.getParameter("class");
					String gather_sum_limit2 = request.getParameter("gather_sum_limit");
					StringTokenizer tokenTO4 = new StringTokenizer(gather_sum_limit2, ",");
					String gather_sum_limit;
					String gather_sum_limit1;
					for (gather_sum_limit = ""; tokenTO4.hasMoreTokens(); gather_sum_limit = (new StringBuilder(String.valueOf(gather_sum_limit))).append(gather_sum_limit1).toString())
						gather_sum_limit1 = tokenTO4.nextToken();

					String gather_period_limit = request.getParameter("gather_period_limit");
					String contact_period_limit = request.getParameter("contact_period_limit");
					String used_customer_name = request.getParameter("used_customer_name");
					String customer_bank = request.getParameter("customer_bank");
					String customer_account = request.getParameter("customer_account");
					String customer_web = request.getParameter("customer_web");
					String customer_tel1 = request.getParameter("customer_tel1");
					String customer_tel2 = request.getParameter("customer_tel2");
					String customer_fax = request.getParameter("customer_fax");
					String customer_postcode = request.getParameter("customer_postcode");
					String contact_person1 = request.getParameter("contact_person1");
					String contact_person1_department = request.getParameter("contact_person1_department");
					String contact_person1_duty = request.getParameter("contact_person1_duty");
					String contact_person1_sex = request.getParameter("contact_person1_sex");
					String contact_person1_office_tel = request.getParameter("contact_person1_office_tel");
					String contact_person1_home_tel = request.getParameter("contact_person1_home_tel");
					String contact_person1_mobile = request.getParameter("contact_person1_mobile");
					String contact_person1_email = request.getParameter("contact_person1_email");
					String contact_person2 = request.getParameter("contact_person2");
					String contact_person2_department = request.getParameter("contact_person2_department");
					String contact_person2_duty = request.getParameter("contact_person2_duty");
					String contact_person2_sex = request.getParameter("contact_person2_sex");
					String contact_person2_office_tel = request.getParameter("contact_person2_office_tel");
					String contact_person2_home_tel = request.getParameter("contact_person2_home_tel");
					String contact_person2_mobile = request.getParameter("contact_person2_mobile");
					String contact_person2_email = request.getParameter("contact_person2_email");
					String register = request.getParameter("register");
					String register_time = request.getParameter("register_time");
					String bodyc = new String(request.getParameter("invoice_info").getBytes("gb2312"), "gb2312");
					String invoice_info = exchange.toHtml(bodyc);
					String bodya = new String(request.getParameter("demand").getBytes("gb2312"), "gb2312");
					String demand = exchange.toHtml(bodya);
					String bodyb = new String(request.getParameter("remark").getBytes("gb2312"), "gb2312");
					String remark = exchange.toHtml(bodyb);
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "crm_file", "customer_id", customer_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "crm_file", "customer_id", customer_ID, "check_tag").equals("9"))
					{
						try
						{
							if (customer_ID == null || customer_ID.equals(""))
								customer_ID = NseerId.getId("crm/file", (String)dbSession.getAttribute("unit_db_name"));
							String sql = (new StringBuilder("update crm_file set chain_id='")).append(chain_id).append("',chain_name='").append(chain_name).append("',customer_name='").append(customer_name).append("',customer_address='").append(customer_address).append("',customer_class='").append(customer_class).append("',type='").append(type).append("',customer_bank='").append(customer_bank).append("',customer_account='").append(customer_account).append("',customer_web='").append(customer_web).append("',customer_tel1='").append(customer_tel1).append("',customer_tel2='").append(customer_tel2).append("',customer_fax='").append(customer_fax).append("',customer_postcode='").append(customer_postcode).append("',used_customer_name='").append(used_customer_name).append("',gather_sum_limit='").append(gather_sum_limit).append("',gather_period_limit='").append(gather_period_limit).append("',contact_period_limit='").append(contact_period_limit).append("',contact_person1='").append(contact_person1).append("',contact_person1_department='").append(contact_person1_department).append("',contact_person1_duty='").append(contact_person1_duty).append("',contact_person1_sex='").append(contact_person1_sex).append("',contact_person1_office_tel='").append(contact_person1_office_tel).append("',contact_person1_home_tel='").append(contact_person1_home_tel).append("',contact_person1_mobile='").append(contact_person1_mobile).append("',contact_person1_email='").append(contact_person1_email).append("',contact_person2='").append(contact_person2).append("',contact_person2_department='").append(contact_person2_department).append("',contact_person2_duty='").append(contact_person2_duty).append("',contact_person2_sex='").append(contact_person2_sex).append("',contact_person2_office_tel='").append(contact_person2_office_tel).append("',contact_person2_home_tel='").append(contact_person2_home_tel).append("',contact_person2_mobile='").append(contact_person2_mobile).append("',contact_person2_email='").append(contact_person2_email).append("',register='").append(register).append("',register_time='").append(register_time).append("',invoice_info='").append(invoice_info).append("',demand='").append(demand).append("',remark='").append(remark).append("',sales_name='").append(sales_name).append("',sales_ID='").append(sales_ID).append("' where customer_ID='").append(customer_ID).append("'").toString();
							crm_db.executeUpdate(sql);
							CdefineUpdate CdefineUpdate = new CdefineUpdate();
							sql = CdefineUpdate.update("crm_file", "customer_ID", customer_ID, request);
							crm_db.executeUpdate(sql);
							if (!chain_id.equals("oldChain_id"))
							{
								sql = (new StringBuilder("select id from crm_file where chain_id='")).append(oldChain_id).append("'").toString();
								ResultSet rs = crm_db.executeQuery(sql);
								if (!rs.next())
								{
									sql = (new StringBuilder("update crm_config_file_kind set delete_tag='0' where file_id='")).append(oldChain_id).append("'").toString();
									crm_db.executeUpdate(sql);
								}
								sql = (new StringBuilder("update crm_config_file_kind set delete_tag='1' where file_id='")).append(chain_id).append("'").toString();
								crm_db.executeUpdate(sql);
							}
						}
						catch (Exception ex)
						{
							ex.printStackTrace();
						}
						response.sendRedirect((new StringBuilder("draft/crm/file_choose_attachment.jsp?customer_ID=")).append(customer_ID).toString());
					} else
					{
						response.sendRedirect("draft/crm/file_ok.jsp?finished_tag=2");
					}
				} else
				{
					response.sendRedirect("draft/crm/file_ok.jsp?finished_tag=1");
				}
				crm_db.commit();
				crm_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception x)
		{
			x.printStackTrace();
		}
	}
}
